home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / WindowMaker / wrlib / view.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-03-06  |  1.7 KB  |  87 lines

  1. #include <X11/Xlib.h>
  2. #include "wraster.h"
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include "tile.xpm"
  6. Display *dpy;
  7. Window win;
  8. RContext *ctx;
  9. RImage *img;
  10. Pixmap pix;
  11.  
  12.  
  13.  
  14. int main(int argc, char **argv)
  15. {
  16.     RContextAttributes attr;
  17.  
  18.     dpy = XOpenDisplay("");
  19.     if (!dpy) {
  20.     puts("cant open display");
  21.     exit(1);
  22.     }
  23.  
  24.     attr.flags = RC_RenderMode | RC_ColorsPerChannel;
  25.     attr.render_mode = RDitheredRendering;
  26.     attr.colors_per_channel = 4;
  27.     ctx = RCreateContext(dpy, DefaultScreen(dpy), &attr);
  28.  
  29.     if (argc<2) 
  30.     img = RGetImageFromXPMData(ctx, image_name);
  31.     else
  32.     img = RLoadImage(ctx, argv[1], 0);
  33.  
  34.     if (!img) {
  35.     puts(RMessageForError(RErrorCode));
  36.     exit(1);
  37.     }
  38.     /*
  39.     if (argc > 2) {
  40.     RImage *tmp = img;
  41.     
  42.     img = RSmoothScaleImage(tmp, tmp->width*atol(argv[2]), 
  43.                 tmp->height*atol(argv[2]));
  44.     RDestroyImage(tmp);
  45.     }
  46.      */
  47.  
  48.     if (argc > 2) {
  49.     img = RScaleImage(img, img->width*atof(argv[2]), 
  50.               img->height*atof(argv[2]));
  51.     }
  52.     
  53.     {
  54.     RImage *tmp = RCreateImage(200, 200, True);
  55.     RColor col = {0,0,255,255};
  56.     
  57.     if (img->format == RRGBAFormat)
  58.         puts("aklpha");
  59.     else
  60.         puts("no alpha");
  61.     
  62.     RClearImage(tmp, &col);
  63.     
  64.     RCombineArea(tmp, img, 0, 0, 20, 20, 10, 10);
  65.     img = tmp;
  66.     }
  67.  
  68.     
  69.     if (!RConvertImage(ctx, img, &pix)) {
  70.     puts(RMessageForError(RErrorCode));
  71.     exit(1);
  72.     }
  73.     
  74.     printf("%ix%i\n", img->width, img->height);
  75.        
  76.        
  77.  
  78.     win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 
  79.                   400, 400, 0, 0, 0);
  80.     XSetWindowBackgroundPixmap(dpy, win, pix);
  81.     XClearWindow(dpy, win);
  82.     XMapRaised(dpy, win);
  83.     XFlush(dpy);
  84.     getchar();
  85.     exit(0);
  86. }
  87.